﻿using System;
using System.Windows.Forms;

namespace Amgine
{
    public partial class DeleteAllChildrenForm : Form
    {
        private string tableName;

        public DeleteAllChildrenForm(string tableName)
        {
            InitializeComponent();
            this.tableName = tableName;
        }

        private void button_confirm_Click(object sender, EventArgs e)
        {
            if (deleteAllByTableName(checkBox_is_delete_group.Checked))
            {
                DialogResult = DialogResult.OK;
            }
            else
            {
                DialogResult = DialogResult.Retry;
            }
            Close();
        }

        private bool deleteAllByTableName(bool isDeleteGroup)
        {
            if (DBHelper.TABLE_ACCOUNT.Equals(tableName))
            {
                return DBHelper.deleteAllAccount(isDeleteGroup);
            }
            else if (DBHelper.TABLE_LINKMAN.Equals(tableName))
            {
                return DBHelper.deleteAllLinkman(isDeleteGroup);
            }
            else if (DBHelper.TABLE_TOOL.Equals(tableName))
            {
                return DBHelper.deleteAllTools(isDeleteGroup);
            }
            else
            {
                return false;
            }
        }

        private void button_cancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }
    }
}
